#include <stdio.h>
#include <unistd.h>

int g_val = 10;

int main()
{
    pid_t id = fork();

    if(id == 0)
    {
        int cut = 5;
        while(1)
        {
            printf("i am a child  pid = %d ppid = %d g_val = %d  &g_val = %p\n",getpid(),getppid(),g_val,&g_val);
            cut--;
            if(cut == 0)
            {
                g_val = 20;
                printf("child:g_val 10 -> 20\n");
    
            }
        sleep(1);
        }
    }
    else 
    {

        while(1)
        {
           
            printf("i am a father  pid = %d ppid = %d g_val = %d  &g_val = %p\n",getpid(),getppid(),g_val,&g_val);
            sleep(1);
        }
    }

    return 0;
}
